package com.small.site.controller;

import com.small.site.aspect.annotation.Log;
import com.small.site.pojo.SysLog;
import com.small.site.service.LogService;
import com.small.site.util.R;
import com.small.site.vo.PageVo;
import com.small.site.vo.req.LogPageReqVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaochi
 * @date 2021/12/16 12:38
 * @desc LogController
 */
@RestController
@RequestMapping("/manager")
public class LogController extends BaseController{

    @Autowired
    private LogService logService;

    /**
     * 分页查找操作日志
     * @param logPageReqVo
     * @return
     */
    @PreAuthorize("hasAuthority('sys:log:list')")
    @PostMapping("/logs/v1")
    public R<PageVo<SysLog>> pageInfo(@RequestBody LogPageReqVo logPageReqVo){
        return R.ok(logService.findPage(logPageReqVo));
    }

    @PreAuthorize("hasAuthority('sys:log:delete')")
    @Log(title = "系统管理-日志管理",action = "删除日志接口")
    @DeleteMapping("/log/v1")
    public R<String> deletedLog(@RequestBody List<String> logIds){
        return logService.deletedLog(logIds);
    }
}
